//
// Created by yyancy on 2019/10/27.
//
#include <stdio.h>
#include <stdlib.h>
#include "letter.h"

ADDR *del(ADDR *top) {
    display(top);
    printf("请输入要删除的编码\n");
    int c;

    c = getchar();
    while (getchar() != '\n');
    int i = c - '1';
    ADDR *cur, *parent;
    printf("%d", i);
    for (cur = top->next, parent = top; cur != NULL && i > 0; parent = cur, cur = cur->next, i--) {
    }
    if (cur == NULL) {
        printf("未找到相关编号\n");
        return top;
    } else {
        printf("删除信息: %c\tname=%s\ttel=%s\n", c, cur->name, cur->tel);
        parent->next = cur->next;
        cur->next = NULL;
        free(cur);
    }
    return top;
}